home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / DDJMAG / DDJ9310.ZIP / DFPP03.ZIP / STATBAR.CPP < prev    next >
C/C++ Source or Header  |  1993-09-14  |  1KB  |  71 lines

  1. // ------------- statbar.cpp
  2.  
  3. #include <time.h>
  4. #include <stdlib.h>
  5. #include "statbar.h"
  6.  
  7. static Color col = {
  8.     BLACK,CYAN,
  9.     BLACK,CYAN,
  10.     BLACK,CYAN,
  11.     BLACK,CYAN
  12. };
  13.  
  14. StatusBar::StatusBar(DFWindow *par)    : TextBox( par->ClientLeft(),
  15.                                                 par->Bottom(),
  16.                                                   1,
  17.                                                   par->ClientWidth(),
  18.                                                   par)
  19. {
  20.     windowtype = StatusbarWindow;
  21.     SetAttribute(FRAMEWND);
  22.     colors = col;
  23. }
  24.  
  25. void StatusBar::ParentSized(int xdif, int ydif)
  26. {
  27.     Size(Right()+xdif, Top());
  28.     Move(Left(), Bottom()+ydif);
  29. }
  30.  
  31. void StatusBar::ClockTick()
  32. {
  33.     static Bool flipflop = False;
  34.     time_t t = time(0);
  35.     struct tm *now = localtime(&t);
  36.     int hr = now->tm_hour > 12 ?
  37.             now->tm_hour - 12 :
  38.             now->tm_hour;
  39.     if (hr == 0)
  40.         hr = 12;
  41.     int mn = now->tm_min;
  42.     char hm[3];
  43.     itoa(hr, hm, 10);
  44.     String timestr(hm);
  45.     timestr += ":";
  46.     if (mn < 10)
  47.         timestr += "0";
  48.     itoa(mn, hm, 10);
  49.     timestr += hm;
  50.     timestr += (now->tm_hour > 11 ? "pm " : "am ");
  51.     timestr += " ";
  52.     /* ------- blink the : at one-second intervals ----- */
  53.     if (flipflop)    {
  54.         timestr[hr < 10 ? 1 : 2] = ' ';
  55.         flipflop = False;
  56.     }
  57.     else
  58.         flipflop = True;
  59.     int x = ClientWidth() - 8;
  60.     WriteClientString(timestr, x, 0, colors.fg, colors.bg);
  61. }
  62.  
  63. void StatusBar::StatusMessage(String& Msg)
  64. {
  65.     int x = (ClientWidth() - Msg.Strlen()) / 2;
  66.     WriteClientString(Msg, x, 0, colors.fg, colors.bg);
  67. }
  68.  
  69.  
  70.  
  71.